export default {
	data() {
		return {
			shareConfig: {
				title: '工业招商顾问客户资源管理小程序',
				path: '', // 动态设置
				imageUrl: '',
			},
		};
	},
	onLoad() {
		// 设置默认分享内容
		uni.showShareMenu({
			withShareTicket: true,
			menus: ['shareAppMessage', 'shareTimeline']
		});
	},
	methods: {
		// 动态设置分享内容（可在页面调用）
		setShareConfig({
			title,
			path,
			imageUrl
		}) {
			if (title) this.shareConfig.title = title
			if (path) this.shareConfig.path = path
			if (imageUrl) this.shareConfig.imageUrl = imageUrl
		},
	},
	onShareAppMessage() {
		const pages = getCurrentPages()
		const currentPage = pages[pages.length - 1]
		const route = `/${currentPage.route}` // 当前页面路径
		const query = currentPage.options || {} // 当前页面参数
		var sharePath = ''
		sharePath = `${route}?${Object.keys(query)
		.map(key => `${key}=${encodeURIComponent(query[key])}`)
		.join('&')}`
		if (route != '/sub_index/index/xmdetail') {
			return {
				title: this.shareConfig.title,
				path: `pages/index/index`, // 分享路径，可携带参数
			};
		}
		return {
			title: this.shareConfig.title,
			path: sharePath || this.shareConfig.path,
		};
	},
	onShareTimeline() {
		return {
			title: "敏智云康小程序",
			path: `pages/index/index`, // 分享路径，可携带参数
		};
	}
}